//
//  SiteUpViewController.swift
//  elarc01
//
//  Created by elarc on 16/2/26.
//  Copyright © 2016年 elarc. All rights reserved.
//

import UIKit

class SiteUpViewController: BaseUIViewController{

    
    let rippleView = UIView()
    let particlesView = UIImageView()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.whiteColor()
        // Do any additional setup after loading the view.
        buildRippleView()
        buildParticles()
    }
 //水波纹
    func buildRippleView () {
        rippleView.frame = CGRectMake(0, 0, 300, 300)
        rippleView.backgroundColor = UIColor.colorWithCustom(20, g: 20, b: 20,alpha: 0.3)
        rippleView.layer.cornerRadius = 150
        rippleView.layer.masksToBounds = true
        rippleView.alpha = 0
    }
    
  //粒子
    func buildParticles(){
        
        particlesView.frame = CGRectMake(0, 0, ScreenWidth, ScreenHeight)
        particlesView.image = UIImage(named: "rain")
        particlesView.contentMode = UIViewContentMode.ScaleAspectFill
        self.view.addSubview(particlesView)
        
    //火星飘落
        
        let fireLayer = CAEmitterLayer()
        fireLayer.emitterPosition = CGPointMake(100, -30)
        fireLayer.emitterSize = CGSizeMake(self.view.bounds.size.width * 2, 0)
        fireLayer.emitterMode = kCAEmitterLayerOutline
        fireLayer.emitterShape = kCAEmitterLayerLine
    
        let fireCell = CAEmitterCell()
        let fireimage = UIImage(named: "panda02")
        fireCell.contents = fireimage!.CGImage
        // 火星缩放比例
        fireCell.scale = 0.02;
        fireCell.scaleRange = 0.5;
        
        // 每秒产生的火星数量
        fireCell.birthRate = 7;
        fireCell.lifetime = 80;
        
        // 每秒火星变透明的速度
        fireCell.alphaSpeed = -0.01;
        
        // 秒速“五”厘米～～
        fireCell.velocity = 40;
        fireCell.velocityRange = 60;
        
        // 火星掉落的角度范围
        fireCell.emissionRange = CGFloat(M_PI)
        
        // 火星旋转的速度
        fireCell.spin = CGFloat(M_PI_4)
        
        // 每个cell的颜色
        //    snowCell.color = [[UIColor redColor] CGColor];
        
        // 阴影的 不透明 度
        fireLayer.shadowOpacity = 1;
        // 阴影化开的程度（就像墨水滴在宣纸上化开那样）
        fireLayer.shadowRadius = 8;
        // 阴影的偏移量
        fireLayer.shadowOffset = CGSizeMake(3, 3);
        // 阴影的颜色
        fireLayer.shadowColor = UIColor.whiteColor().CGColor
        
        
        fireLayer.emitterCells = [fireCell]
        particlesView.layer.addSublayer(fireLayer)

    }
    
    
    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
        for touch: AnyObject in touches {
        let touch:UITouch = touch as! UITouch
        let location:CGPoint = touch.locationInView(self.view)
        view.addSubview(rippleView)
        rippleView.center = location
        rippleView.transform = CGAffineTransformMakeScale(0.5, 0.5)
        [UIView.animateWithDuration(0.1) { () -> Void in
            self.rippleView.alpha = 1
            self.view.alpha = 0.3
            }];
        UIView.animateWithDuration(0.7, delay: 0, options: UIViewAnimationOptions.CurveEaseInOut, animations: { () -> Void in
            self.rippleView.transform = CGAffineTransformMakeScale(1, 1)
            self.rippleView.alpha = 0
            self.view.alpha = 1
            }) { (finished) -> Void in
                self.rippleView.removeFromSuperview()
        }
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
